
import Request from 'luch-request'

const httpGraphql = new Request()


//请求拦截器
httpGraphql.interceptors.request.use((config) => { // 可使用async await 做异步操作
	//const token = uni.getStorageSync('token');
	// if (token) {
	config.header = {
		Authorization: "xxxxxxx",
		"x-hasura-admin-secret":'myadminsecretkeyweipengyu'
	}
	//}

	if (config.method === 'POST') {
	    config.data = JSON.stringify(config.data);
	}

    // console.log("请求拦截器");
	return config
}, error => {
	return Promise.resolve(error)
})

// 响应拦截器
httpGraphql.interceptors.response.use((response) => {

	console.log(response,"响应拦截器");

	let res = {}
	if(response&&response.statusCode===200){
		res.code = 200,
		res.msg="ok",
		res.data=response.data.data
	}else{
		res.code = 0,
		res.msg="error",
		res.data=''
	}

   
	return res
}, (error) => {
	//未登录时清空缓存跳转
	// if (error.statusCode == 401) {
	//     uni.clearStorageSync();
	//     uni.switchTab({
	//         url: "/pages/index/index.vue"
	//     })
	// }

  

	return Promise.resolve(error)
})


export default httpGraphql



